﻿using HarmonyLib;
using RimWorld;
using System.Reflection;
using UnityEngine;
using Verse;

namespace Miao.Stand
{
    public class Stand : Mod
    {
        public static Stand_Settings Settings { get; internal set; }
        public static Stand ModSingleton { get; private set; }

        public Texture2D LoadIcon(string name, string prefix = "Icon/")
        {
            return Stand.ModSingleton.Content.GetContentHolder<Texture2D>().Get(prefix + name);
        }

        public Stand(ModContentPack content) : base(content)
        {
            Settings = this.GetSettings<Stand_Settings>();
            ModSingleton = this;
            var harmony = new Harmony("Miao.Stand");
            harmony.PatchAll(Assembly.GetExecutingAssembly());//日，副武器也是用这种方式添加Harmony的

            var type = typeof(StandVerbAbilityPathches);

            harmony.Patch(AccessTools.PropertyGetter(typeof(Verb), nameof(Verb.DirectOwner)),//类型设置
               prefix: new HarmonyMethod(type, nameof(StandVerbAbilityPathches.get_DirectOwner_Prefix)));

            harmony.Patch(AccessTools.Method(typeof(Targeter), "ConfirmStillValid"),
                prefix: new HarmonyMethod(type, nameof(StandVerbAbilityPathches.ConfirmStillValid)));
        }
        public override string SettingsCategory()//设置本地化类别
        {
            //return base.SettingsCategory();
            return "StandMaster".Translate();
        }
        
        public override void DoSettingsWindowContents(Rect inRect)//这个是画控制台
        {
            Listing_Standard listingStandard = new Listing_Standard();
            listingStandard.Begin(inRect);
            listingStandard.Label("替身觉醒成功概率".Translate());
            Settings.AwakeStandProbability = listingStandard.Slider(Settings.AwakeStandProbability, 0, 1);
            listingStandard.CheckboxLabeled("替身范围是否由精神力决定".Translate(), ref Settings.StandRangeDistanceIsConsciousness);
            listingStandard.CheckboxLabeled("替身在敌人倒地时仍继续欧拉欧拉吗？".Translate(), ref Settings.OraOraToDead);

            
            //if (Settings.StandRangeDistanceIsConsciousness)
            //{
            //    Settings.StandRangeDistance = float.Parse(listingStandard.TextEntryLabeled("替身范围", Settings.StandRangeDistance.ToString()));
            //    //listingStandard.TextFieldNumeric(ref listingStandard, ref 缓冲, 0, 5f);
            //}
            //listingStandard.CheckboxLabeled("只有替身才能攻击替身".Translate(), ref Settings.StandCanAttackStand);
            //listingStandard.CheckboxLabeled("伤害互相同步".Translate(), ref Settings.StandOwnerBodySync);
            listingStandard.End();
            base.DoSettingsWindowContents(inRect);
        }
    }
}
